package com.ml.mall.service.category.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ml.mall.bean.page.Page;
import com.ml.mall.bean.req.category.SuggestedCategoryNewDto;
import com.ml.mall.bean.req.category.SuggestedCategoryQueryPageDto;
import com.ml.mall.bean.res.category.SuggestedCategoryQueryPageRes;
import com.ml.mall.entity.category.SysSuggestedCategory;
import com.ml.mall.entity.sys.SysUser;
import com.ml.mall.security.JwtUtil;
import com.ml.mall.service.category.SysSuggestedCategoryService;
import com.ml.mall.mapper.SysSuggestedCategoryMapper;
import com.ml.mall.utils.MyBatisUtil;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class SysSuggestedCategoryServiceImpl extends ServiceImpl<SysSuggestedCategoryMapper, SysSuggestedCategory>
    implements SysSuggestedCategoryService{
    @Override
    public Boolean createSuggestedCategory(SuggestedCategoryNewDto dto) {
        SysUser currentUser = JwtUtil.getCurrentUser();

        SysSuggestedCategory sysSuggestedCategory = new SysSuggestedCategory();
        BeanUtil.copyProperties(dto, sysSuggestedCategory);
        sysSuggestedCategory.setCreator(currentUser.getAcc());

        return save(sysSuggestedCategory);
    }

    @Override
    public Page<SuggestedCategoryQueryPageRes> queryPage(SuggestedCategoryQueryPageDto dto) {
        //分页查询结果
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysSuggestedCategory> queryPage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(dto.getPageIndex(), dto.getPageNum());
        page(queryPage);

        //结果转化
        return MyBatisUtil.parsePageResult(queryPage, SuggestedCategoryQueryPageRes.class);
    }
}




